package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsAutoScanService;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: JW
 * @Description: TODO
 * @DateTime: 2022-02-11 20:42
 **/
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    @Autowired
    private WmNewsAutoScanService wmNewsAutoScanService;

    /**
     * @Author: JW
     * @Description:  TODO 文章列表
     * @Date: 22:02 2022-02-11
     * @Param: [wmNewsPageReqDto]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/list")
    public ResponseResult getList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){

        return wmNewsService.getList(wmNewsPageReqDto);
    }

    /**
     * @Author: JW
     * @Description:  TODO 发布文章 && 修改文章
     * @Date: 22:03 2022-02-11
     * @Param: [wmNewsDto]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto){

        ResponseResult responseResult = wmNewsService.submitNews(wmNewsDto);

        //拿到文章id
        String id = responseResult.getData().toString();

        //进行审核(异步)
        wmNewsAutoScanService.autoScanWmNews(Integer.parseInt(id));

        return responseResult;
    }


    /**
     * @Author: JW
     * @Description:  TODO 上架 && 下架
     * @Date: 20:32 2022-02-17
     * @Param: [dto]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){

        return wmNewsService.downOrUp(wmNewsDto);
    }
}
